package org.kangjia;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import org.kangjia.exportFile.ExportExcel;
import org.kangjia.hook.ExcelImportHandler;
import org.kangjia.importFile.ImportExcel;
import org.kangjia.importFile.ImportResult;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

public class ImportBuild<T> {

    private InputStream is;

    private Class<T> clazz;

    private Integer titleRowNum;

    private ExcelImportHandler<T> handler;

    private String sheetName;

    private Integer cacheSize;

    private Integer saveFailThreshold;

    public class Build{

        public ImportResult execute() throws Exception {
            return new ImportExcel<T>(is, clazz, sheetName, titleRowNum, cacheSize, saveFailThreshold, handler).execute();
        }
    }

    public ImportBuild() {}

    public ImportBuild(InputStream is, Class<T> clazz, Integer titleRowNum, ExcelImportHandler<T> handler) {
        this.is = is;
        this.clazz = clazz;
        this.titleRowNum = titleRowNum;
        this.handler = handler;
    }

    public ImportBuild<T> setIs(InputStream is) {
        this.is = is;
        return this;
    }

    public ImportBuild<T> setClazz(Class<T> clazz) {
        this.clazz = clazz;
        return this;
    }

    public ImportBuild<T> setTitleRowNum(Integer titleRowNum) {
        this.titleRowNum = titleRowNum;
        return this;
    }

    public ImportBuild<T> setHandler(ExcelImportHandler<T> handler) {
        this.handler = handler;
        return this;
    }

    public ImportBuild<T> setSheetName(String sheetName) {
        this.sheetName = sheetName;
        return this;
    }

    public ImportBuild<T> setCacheSize(Integer cacheSize) {
        this.cacheSize = cacheSize;
        return this;
    }

    public ImportBuild<T> setSaveFailThreshold(Integer saveFailThreshold) {
        this.saveFailThreshold = saveFailThreshold;
        return this;
    }

    public Build Build(){
        return this.new Build();
    }
}
